#!/usr/bin/env python




import time
from optparse import OptionParser
from multiprocessing import Process


from dexen.system.server import archive_server
from dexen.system.server import service as srv_svc
from dexen.system.registry import service as reg_svc


def start():
    parser = OptionParser("server [OPTIONS]...")
    parser.add_option("-n", "--name", dest="reg_name", default="dexen_server", metavar="SERVER_NAME",
                      help="gives logical name to the server. Default dexen_server")
    (options, args) = parser.parse_args()
    if len(args) > 0:
        parser.error("Positional argument is not expected.")
        
    reg = Process(target=reg_svc.start, name="DEXEN_REG", args=(options.reg_name, 
                                                                options.reg_name == "local"))
    arc_server = Process(target=archive_server.start, name="DEXEN_ARC_SERVER")
    reg.start()
    arc_server.start()
    time.sleep(2)
    print "I am starting server service"
    srv_svc.start(options.reg_name == "local")

def main():
    start()

if __name__ == "__main__":
    main()